package tests;

import static org.junit.Assert.*;

import java.net.Socket;
import java.util.ArrayList;

import model.Client;
import model.Email;
import model.Server;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
 * This class tests the Server class.
 * 
 * @author b_aldosa
 * @since June 17 2013
 *
 */
public class TestServer {

	Server SUT;
	ArrayList<Email> emails;
	Client client;
	Socket socket;
	
	/**
	 * This method is called before every test case to initialize the objects
	 */
	@Before
	public void setUp()
	{
		SUT=new Server();
		emails=new ArrayList<Email>();
		Email email=new Email();
		email.setTo("bee");
		email.setPendingRecepients("bee");
		emails.add(email);
		SUT.setEmailsToSend(emails);
		socket=new Socket();
		client=new Client("bee", socket);
		SUT.getConnectedClients().add(client);
	}
	/**
	 * This method is called after every test case to 
	 * nullify objects.
	 */
	@After
	public void tearDown()
	{
		SUT=null;
	}
	
	/**
	 * This test case tests the get port method
	 */
	@Test
	public void testGetPort() {
		assertEquals(6789,SUT.getPort());
	}
	/**
	 * This test case tests the get emails to 
	 * send method
	 */
	@Test
	public void testGetEmailsToSend() {
	assertEquals(1,SUT.getEmailsToSend().size());
	}
	/**
	 * This test case tests the get pending emails for
	 * method
	 */
	@Test
	public void testGetPendingEmailsFor() {
		ArrayList<Email> result=new ArrayList<Email>();
		
		result=SUT.getPendingEmailsFor("bee");
		assertEquals(1,result.size());
	}
	/**
	 * This test case tests the get connected clients method
	 */
	@Test
	public void testGetConnectedClients() {
		
		assertEquals(1,SUT.getConnectedClients().size());
	}
	/**
	 * This test case tests the get client method
	 */
	@Test
	public void testGetClient() {
		assertEquals(client,SUT.getClient("bee"));
	}


}
